<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" name="username">
    <br><br>
    <input type="password" name="userpwd">
    <br><br>
    <button>登录</button>


    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('input[type="text"]') ;
        const oPwd = document.querySelector('input[type="password"]') ;

        oBtn.onclick = function() {
            const username = oUser.value ; 
            const userpwd = oPwd.value ;
            if(username && userpwd) {
                const xhr = new XMLHttpRequest() ;
                xhr.open('get' , `../php/06login.php?username=${username}&userpwd=${userpwd}` , true) ;
                xhr.send() ;
                xhr.onreadystatechange = function() {
                    if(xhr.readyState === 4 && xhr.status === 200) {
                        let data = xhr.responseText ;
                        console.log(data);
                        data = JSON.parse(data) ;
                        console.log(data);
                        const {status , msg} = data ;
                        if(status) {
                            // 把用户信息存入 cookie  或者  localStorage
                            // location.href = ''
                        } else {
                            alert(msg) ;
                        }
                    }
                }
            }
        }


       


    </script>
    
</body>
</html>